package de.hwrBerlin.dataMining.view;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import de.hwrBerlin.dataMining.constants.Images;
import de.hwrBerlin.dataMining.constants.UIConstants;
import de.hwrBerlin.dataMining.dataStructure.TreeNode;

public class FullScreenTreeView {

	private TreeZoomView _treeZoomView;

    public FullScreenTreeView(Display pDisplay, int pStyle, TreeNode pTreeNode) {
		final Shell shell = new Shell(pDisplay, pStyle);
		Display display = shell.getDisplay();

		shell.setLayout(new GridLayout(1, true));
		shell.setText(UIConstants.TITLE);
		shell.setImages(Images.LOGO_ICONS);
        //close-Button

        Button closeButton = new Button(shell, SWT.PUSH);
        closeButton.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false));
        closeButton.setImage(new Image(null, Images.CLOSE_FULLSCREEN));
        closeButton.setToolTipText(UIConstants.CLOSE_FULL_SCREEN);
        closeButton.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent pE) {
                shell.close();
//                System.out.println();
            }
        });

        // TreePainter und Zoom
        _treeZoomView = new TreeZoomView(shell, SWT.BORDER, null);
        _treeZoomView.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
        
		_treeZoomView.getTreePainter().repaint(pTreeNode);
		_treeZoomView.getTreePainter().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

//		Der Keylistener funktioniert nicht, wenn die Buttons fokusiert sind.
//		
//		Label howToClose = new Label(shell, SWT.NONE);
//		howToClose.setText(UIConstants.HOW_TO_CLOSE);
//		howToClose.setLayoutData(new GridData(SWT.NONE, SWT.NONE, false, false));
//
//		shell.addKeyListener(new KeyAdapter() {
//			@Override
//			public void keyPressed(KeyEvent e) {
//				if (e.keyCode == 27) {
//					shell.close();
//					System.out.println();
//				}
//			}
//		});

		shell.setMaximized(true);
		shell.setFullScreen(true);
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}
}
